package xq.gwt.ui.widgets.command;

import xq.gwt.mvc.model.CommandModel;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.layout.HStack;

public class HorisontalButtonsCommandListPresenter implements CommandListPresenter {
	protected HStack buttonLayout;
	
	
	public HorisontalButtonsCommandListPresenter(){
		buttonLayout = new HStack();		
		buttonLayout.setMargin(2);
		buttonLayout.setAlign(Alignment.RIGHT);
	}
	
	public HorisontalButtonsCommandListPresenter(Alignment align){
		buttonLayout = new HStack();		
		buttonLayout.setMargin(2);
		buttonLayout.setAlign(align);
	}
	
	@Override
	public void setCommands(CommandModel[] commands) {
		buttonLayout.clear();
		if(commands == null) {
			return;
		}
		
		for (int i = 0; i < commands.length; i++) {
			ButtonCommandPresenter commandButton = new ButtonCommandPresenter();
			commandButton.setModel(commands[i]);			
			buttonLayout.addMember(commandButton.getButton());
		}
	}

	@Override
	public Canvas getCanvas() {		
		return buttonLayout;
	}

}
